<?php
/**
 * Created by PhpStorm.
 * User: liang
 * Date: 2022/10/19
 * Time: 10:45
 */

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class SaleUserLogin extends Model
{
    use HasFactory;

    protected $table = 'sp_sale_user_login';
    protected $primaryKey = 'id';
    public $timestamps = false;
    //查询分销商账号信息-单条
    protected function GetSaleUser($where)
    {
        $data = $this
            ->where($where)
            ->first();
        $data = $data ? $data->toArray() : array();
        return $data;
    }
    //查询分销商账号信息-多条
    protected function GetSaleUsers($pageSize,$where)
    {
        $data = $this
            ->where($where)
            ->orderBy('create_time', 'desc')
            ->paginate($pageSize);
        $data = $data ? $data->toArray() : array();
        return $data;
    }
    //查询分销商详细信息
    protected function GetSaleList($pageSize,$where)
    {
        $data = $this
            ->from('sp_sale_user_login as l')
            ->leftjoin('sp_sale_user as u', 'u.sale_user_id','l.sale_user_id')
            ->select(
                'l.id','l.username','l.mobile','l.create_time'
                ,'u.faname'
                )
            ->where($where)
            ->orderBy('l.create_time', 'desc')
            ->paginate($pageSize);
        $data = $data ? $data->toArray() : [];
        return $data;
    }
}
